/*
 * Project: Sudoku Explainer
 * Copyright (C) 2006-2007 Nicolas Juillerat
 * 
 * Project: Sudoku Hint Engine for Android
 * Copyright (C) 2010-2013 Emanuel Moecklin
 * 
 * Available under the terms of the Lesser General Public License (LGPL)
 */
package com.onegravity.sudoku.solver.accumulator;

import java.util.ArrayList;
import java.util.List;

import com.onegravity.sudoku.solver.core.Hint;

/**
 * Hints accumulator, that accumulates a single hint (the first that
 * is received) and then stops.
 */
public class SingleHintAccumulator implements HintsAccumulator {

    private final List<Hint> hints;

    public SingleHintAccumulator() {
        super();
        hints = new ArrayList<Hint>();
    }

	@Override
    public void add(Hint hint) throws StopHintProductionException {
        if (hints.size()==0) {
        	hints.add(hint);
            throw new StopHintProductionException();
        }
    }

    /**
     * Get the only hint that has been accumulated, or <tt>null</tt> if no
     * hint has been received at all.
     * @return the only hint that has been collected
     */
    public Hint getHint() {
        return (hints.size()>0) ? hints.get(0) : null;
    }

	@Override
	public List<Hint> getHints() {
		return hints;
	}

}